<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<!--载入编辑器-->
	<script type="text/javascript" charset="utf-8" src="PUBLIC/ueditor1_4_3/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="PUBLIC/ueditor1_4_3/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="PUBLIC/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	<!--载入uploadify相关文件-->
	<script type="text/javascript" src="PUBLIC/uploadify/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="PUBLIC/uploadify/jquery.uploadify.min.js"></script>
	<link href="PUBLIC/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
	<!--载入hdjs-->
	<link rel="stylesheet" type="text/css" href="PUBLIC/hdjs/hdjs.css"/>
    <script src="PUBLIC/hdjs/hdjs.min.js" type="text/javascript" charset="utf-8"></script>
    <style type="text/css">
		li{
			list-style: none;
			float: right;
		}
		
	</style>
<!--异步调取规格和属性-->
	<script type="text/javascript">
		$(function(){
			var category_cid=<?php echo $goodsData['category_cid']?>;
			var clone=$('#spec').clone();
			var cloAttr=$("#attr").clone();
			$('select[name=category_cid]').change(function(){
				var pocid=$(this).val();
				if(pocid==category_cid) {
                    $("#spec").html(clone);
                    $("#attr").html(cloAttr);
                    return;
                };
				var ID = $(':selected').attr('ID');
				$('input[name=type_ID]').val(ID);
				$.post("<?php echo U('getAttrSpec')?>",{ID:ID},function(data){
					//$typeAttrData
					//属性
					var attr = '';
					//规格
					var spec = '';
					$.each(data, function(k,v) {  
						//1表示规格  ,0表示属性
						if(v.taclass==0)
						{
							attr += '<tr><td>' + v.taname + '</td><td><select name="attr[' + v.taid + ']"><option value="0">请选择</option>';
							$.each(v.tavalue,function(kk,vv){
								attr += '<option value=" ' + vv + '">' + vv + '</option>';
							}) 
							attr += '</select></td><td></td></tr>';
						}else
						{
							spec += '<tr><td>' + v.taname + '</td><td><select name="spec[' + v.taid + '][tavalue][]"><option value="0">请选择</option>';
							$.each(v.tavalue,function(kk,vv){
								spec += '<option value="'+vv+'">' +vv+ '</option>';
							});
							spec += '</select></td><td>附加价格</td><td><input type="text" name="spec[' + v.taid + '][added][]"></td><td><a href="javascript::" class="hd-btn hd-btn-success hd-btn-xm add-spec">添加</a></td></tr>';
						}  
						$('#attr').html(attr);  
						$('#spec').html(spec);                                                
					});
				})
			})
		})
	</script>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">
	<form action="" method='post' enctype="multipart/form-data" id="add_goods">
			<h2 class="hd-title-header">修改商品</h2>
			<table class='hd-table hd-table-form'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="category_cid">
								<?php foreach ($cateData as $k=>$v){?>
									<option value="<?php echo $v['cid']?>" ID="<?php echo $v['type_ID']?>" <?php if($goodsData['category_cid']==$v['cid']){?>
                selected
               <?php }?> ><?php echo $v['_cname']?></option>					
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="brand_bid">
								<option value="0">-请选择-</option>
								<?php foreach ($brandData as $k=>$v){?>
									<option value="<?php echo $v['bid']?>" <?php if($goodsData['brand_bid']==$v['bid']){?>
                selected
               <?php }?> ><?php echo $v['bname']?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' value="<?php echo $goodsData['gname']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>商品货号</td>
						<td>
							<input type="text" name='gnumber' value="<?php echo $goodsData['gnumber']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value="<?php echo $goodsData['unit']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='marketprice' value="<?php echo $goodsData['marketprice']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='shopprice' value="<?php echo $goodsData['shopprice']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='gclick' value="<?php echo $goodsData['gclick']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>库存</td>
						<td>
							<input type="text" name='gtotal' value="<?php echo $goodsData['gtotal']?>"/>
						</td> 
					</tr>
				</tbody>
			</table>
			<p class="hd-title-header">商品属性</p>
			<table class="hd-table hd-table-form" id='attr'>
					<?php foreach ($typeAttr as $k=>$v){?>
					<?php if($v['taclass']==0){?>
                
						<tr>
							<td><?php echo $v['taname']?></td>
							<td>
								<select name="attr[<?php echo $v['taid']?>]">
									 <option value="0">请选择</option>
									<?php foreach ($v['tavalue'] as $kk=>$vv){?>
										<option value="<?php echo $vv?>" <?php if(in_array($vv,$typeAttrGavalue)){?>
                selected
               <?php }?>><?php echo $vv?></option>										
									<?php }?>
								</select>
							</td>
						</tr>
					
               <?php }?>
					
				<?php }?>
			</table>
			<p class="hd-title-header">商品规格</p>
			<table class="hd-table hd-table-form" id='spec'>
				<?php foreach ($goodsAttrData as $k=>$v){?>
					<?php if($v['taclass']==1){?>
                
						<tr>
							<td><?php echo $v['taname']?></td>
							<td>
								<select name="spec[<?php echo $v['taid']?>][tavalue][]">
									 <option value="0">请选择</option>
									<?php foreach ($v['tavalue'] as $kk=>$vv){?>
										<option value="<?php echo $vv?>" <?php if($v['gavalue']==$vv){?>
                selected
               <?php }?> ><?php echo $vv?></option>										
									<?php }?>
								</select>
								<td>附加价格</td>
								<td><input type="text" name="spec[<?php echo $v['taid']?>][added][]" value="<?php echo $v['added']?>"/></td>
								<td>
									<a href="javascript:;" class="hd-btn hd-btn-primary hd-btn-xm add-spec">增加</a>
									<a href="javascript:;" class="hd-btn hd-btn-danger hd-btn-xm del-spec">删除</a>
								</td>
							</td>
						</tr>
					
               <?php }?>
					
				<?php }?>
			</table>
			
			<p class="hd-title-header">列表图</p>
			<table class='hd-table hd-table-form'>
				<tr class="info">
					<td>上传图片</td>
					<td class="list">
						<input id="file" type="file" multiple="true" />
	            		 <span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
			             <script type="text/javascript">
			                $(function() {
			                    $('#file').uploadify({
			                        'formData'     : {//POST数据
			                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			                        },
			                        'fileTypeDesc' : '上传文件',//上传描述
			                        'fileTypeExts' : '*.jpg;*.png',
			                        'swf'      : 'PUBLIC/uploadify/uploadify.swf',
			                        'uploader' : "<?php echo U('ajaxUpload')?>",
			                        'buttonText':'选择文件',
			                        'fileSizeLimit' : '2000KB',
			                        'uploadLimit' : 1000,//上传文件数
			                        'width':65,
			                        'height':25,
			                        'successTimeout':10,//等待服务器响应时间
			                        'removeTimeout' : 0.2,//成功显示时间
			                        'onUploadSuccess' : function(file, data, response) {
			                            data=$.parseJSON(data);
			                            var imageUrl = data.image?data.url:'<?php echo __PUBLIC__?>/image/default.png';
			                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70' style='float:left:margin_left:10px;'/><a href='javascript:;' style='color:red' class='del-img1'>X</a>";
			                            li +='<input type="hidden" name="pic" value="'+data.path+'"/>';
			                            li +='</li>';
			                            $("#pic-list").prepend(li);
			                        }
			                    });
			                });
			             </script>
					</td>
					<td id='pic-list'>
						<if value="$goodsData['pic']">
							<li path="{$goodsData.pic}" url="">
									<img src="<?php echo __ROOT__?>/<?php echo $goodsData['pic']?>" class='hd-w80 hd-h70' style="float:left:margin_left:10px;"/>
									<a href="javascript:;" style="color:red;" class="del-img">X</a>
					                <input type="hidden" name="pic" value="<?php echo $goodsData['pic']?>"/>
					        </li>
				        </if>
					</td>
				</tr>
			</table>
			<p class="hd-title-header">商品图册</p>
			<table class='hd-table hd-table-form'>
				<tr class="info">
					<td>上传图片</td>
					<td class="logo-td">
						<input id="file1" type="file" multiple="true" name="photos"/>
	            		 <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
			             <script type="text/javascript">
			                $(function() {
			                    $('#file1').uploadify({
			                        'formData'     : {//POST数据
			                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			                        },
			                        'fileTypeDesc' : '上传文件',//上传描述
			                        'fileTypeExts' : '*.jpg;*.png',
			                        'swf'      : 'PUBLIC/uploadify/uploadify.swf',
			                        'uploader' : '"<?php echo U('ajaxUpload')?>"',
			                        'buttonText':'选择文件',
			                        'fileSizeLimit' : '2000KB',
			                        'uploadLimit' : 1000,//上传文件数
			                        'width':65,
			                        'height':25,
			                        'successTimeout':10,//等待服务器响应时间
			                        'removeTimeout' : 0.2,//成功显示时间
			                        'onUploadSuccess' : function(file, data, response) {
			                            data=$.parseJSON(data);
			                            var imageUrl = data.image?data.url:'<?php echo __PUBLIC__?>/image/default.png';
			                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70' style='float:left:margin_left:10px;'/><a href='javascript:;' style='color:red' class='del-img1'>X</a>";
			                            li +='<input type="hidden" name="photo[]" value="'+data.path+'"/>';
			                            li +='</li>';
			                            $("#photo-list").prepend(li);
			                        }
			                    });
			                });
			             </script>
						
					</td>
					<td id='photo-list'>
						
						<?php foreach ($goodsDetail['big'] as $k=>$v){?>
							<if value="$v">
							<li path="{$v}" url="<?php echo __ROOT__?>/<?php echo $v?>">
								<img src="<?php echo __ROOT__?>/<?php echo $v?>" class='hd-w80 hd-h70' style="float:left:margin_left:10px;"/>
								<a href="javascript:;" style="color:red;" class="del-img">X</a>
				                <input type="hidden" name="photo[]" value="<?php echo $v?>"/>
				            </li>
				            </if>
			            <?php }?>
			           
					</td>
				</tr>
			</table>
			<p class="hd-title-header">商品详细</p>
			<table class='hd-table hd-table-form'>
				<tr class="hide info">
					<td>
						<script id="ed" type="text/plain" style="width:100%;height:300px;" name="intro"><?php echo $goodsDetail['intro']?></script>
	                    <script>
							var ue = UE.getEditor('ed');
						</script>
					</td>
				</tr>
			</table>
			<p class="hd-title-header">售后服务</p>
			<table class='table'>
				<tr class="hide info">
					<td>
						<!--<textarea name="service" id="service"></textarea>-->
						<script id="ed1" type="text/plain" style="width:100%;height:300px;" name="service"><?php echo $goodsDetail['service']?></script>
	                    <script>
							var ue = UE.getEditor('ed1');
						</script>
					</td>
				</tr>
			</table>
			<input type="hidden" name="gid" value="<?php echo $_GET['gid']?>"/>
			<input type="hidden" name="type_ID" id="" value="<?php echo $type_ID?>"/>
			<input type="submit" value="确认修改" class="hd-btn hd-btn-primary" />
	</form>

	</div>
	</div>
	</div>
</body>
</html>